print("Welcome to Programming for Data Science")
Welcome to Programming for Data Science
# Pound symbol indicates the beginning of a comment
""" This is a
multiline comment"""
''' This is a
multiline comment'''
' This is a \nmultiline comment'
print(100)
print("Here we go!")
print('Here we go!')
print("let's start")
100 Here we go! Here we go! let's start
print('let's start')
Input In [4] print('let's start') ^ SyntaxError: unterminated string literal (detected at line 1)
print('let\'s start')
# Define a variable apple_price and assign a value 12 to it
apple_price = 12
print(apple_price)
# Define a floating point variable height and assign a value 5.2
height = 5.2
print(height)
# Define three varibles mark1, mark2, mark3 and assign the values 67,47.5, 86 respectively
mark1, mark2, mark3 = 67, 47.5, 86
print(mark1,'\n', mark2, '\n', mark3)
mark1, mark2 = mark2, mark1
print('mark1 =', mark1, 'mark2 = ', mark2)
# This is like the following code in other prgramming languages
# temp = mark1
# mark1 = mark2
# mark2 = temp
print(mark1, mark2, mark3)
print(mark1, mark2, mark3, sep= ' ')
print(mark1, mark2, mark3, sep='\t')
print(mark1, mark2, mark3, sep='\n')
c1 = complex(2)
print("c1 = ",c1)
c2 = complex(2, 3)
print("c2 = ", c2)
a = 3 + 4j # Define a complex variable a which is asigned a value of 3 + 4j
b = 2 + 5j # Define a complex variable b which is asigned a value of 2 + 5j
print(a)
my_sum = a + b
print(my_sum)
print( 3 + 4j * 2)
print((3 + 4j) * 2)
# Print the real part of a complex nember
print(my_sum.real)
# Print the imaginary part of a complex nember
print(my_sum.imag)
is_raining = True
print(is_raining)
is_raining = 25
print(bool(is_raining))
condition = 1 < 10
print(condition)
print ( bool(condition))
print (bool(False))
print (bool(True))
x = 5
y = 0
print (bool(x))
print (bool(y))
print(bool(-12))
char = 'a'
nullChar = ''
print (bool(char))
print (bool(nullChar))
type¶print(type(True))
print(type(mark1))
print(type(mark2))
mark1 = 60
print(type(mark1))
mark1 = 56.5
print(type(mark1))
x = 10 # x is defined as a integer variable
print(type(x))
y = float(x) # convert x to floating variable and assign it to y
print(type(y))
institute_name = "VIT Chennai"
place = 'Chennai'
print(institute_name, end = ',')
print(place)
bin1 = 0b011 # bin1 is a binary variable asigned a value of 011
print(bin1)
print(bin(bin1))
oct1 = 0o10 # oct1 is an octal variable asigned a value of 8
print(oct1)
print(oct(oct1))
hex1 = 0x16 # hex1 is a hexadecimal number with a value of 16
print(hex1)
print(hex(hex1))
x = input('Enter the value of x: ')
print(type(x))
x = int(x)
print(type(x))
# Alternatively we can also code as follows
y = int(input('Enter the value of y: '))
print(type(y))
# A simple asignmnet
number = 10
print(number)
String = "Name"
print(String)
# Tuple assignment positional
num1, num2 = 56, '45'
print(num1, num2, sep = ',')
# Multiple target assignment
num1 = num2 = 100
print(num1, num2, sep = ',')
# Augmented assignment
num1 += num2
print("num1 = ", num1)
num = 10
id(num)
my_num = 222
result = (my_num % 2) == 0
print(my_num, 'is even -', result)
my_num = 101
print(my_num, 'is even -', my_num % 2 == 0)
These opertors perform bit-by-bit operation on tthe opernds
x = 0b1011 # 11
y = 0b1101 # 13
print(bin(x & y))
print(bin(x | y))
print(bin(x ^ y))
x = 0b001000
print(x >> 1)
print(bin(x >> 1))
print(bin(x))
print( bin( x << 2))
print(bin(x))
Operators in the same box group left to right (except for exponentiation, which groups from right to left).